﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Common;
using System.IO;

namespace EHR18
{
    public partial class FormAddModule : BaseChild
    {
        public string CurrentModule { get {return this.textBox1.Text; } }
        public event Action SaveOK;
        public FormAddModule()
        {
            InitializeComponent();
        }

        private void FormAddModule_Load(object sender, EventArgs e)
        {
            ModuleConfig obj;
            string path2 = Path.GetFullPath(string.Format("./Configs/{0}.xml", "template"));
            if (File.Exists(path2))
            {
                obj = ConfigEx.DeserializeFromXml<ModuleConfig>(path2);              
            }
            else
            {
                obj = new ModuleConfig();
            }
            propertyGrid1.SelectedObject = obj;
        }

        private void btnCommit_Click(object sender, EventArgs e)
        {
            if (CurrentModule.IsNullOrEmpty())
            {
                MessageBox.Show("机种名不能为空");
            }
            else
            { 
                string fileName=Path.Combine( Path.GetFullPath("./Configs"),CurrentModule+".xml");
                ((ModuleConfig)propertyGrid1.SelectedObject).SerializeToXml(fileName);
                if (SaveOK != null)
                    SaveOK();
            }
            Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
